<!DOCTYPE html>
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<html>
<head>
<title>${name_china}模板</title>
<%@include file="/common/head.jsp" %>
<link href="<%=request.getContextPath()%>/static/plugin/fullcalendar/style/fullcalendar.css" rel="stylesheet">
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/fullcalendar/js/calendar-converter.js"></script>
<script src="<%=request.getContextPath()%>/static/plugin/fullcalendar/js/moment.min.js"></script>
<script src="<%=request.getContextPath()%>/static/plugin/fullcalendar/js/fullcalendar.js"></script>
<script src="<%=request.getContextPath()%>/static/plugin/fullcalendar/js/zh-cn.js"></script>
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>
</head>
<body class="iframe-page">
	<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
   </div>
		
	<div id="calendar"></div>  
		
	<script>
	  var  permission = CommonUtil.getPermission('calendar');
	 
		//页面初始化
		$(function() {
	      
			//加载数据
		    $('#calendar').fullCalendar({
		        theme:false,
		        height:420,
		        startParam: 'startParam',
		    	endParam: 'endParam',
		        header: {
		          left: 'prev,today,next',
		          center: 'prevYear prev title next nextYear',
		          //right: 'month,agendaWeek,agendaDay'
		          right: ''
		        },
		        defaultDate: new Date(),
		        // 点击事件 回调函数
		        dayClick : function(date, jsEvent, view) {
		        	var dateStr=date.format();  
		            var sysdate1=new Date();
		            sysdate1.setHours("8","0","0","0");
		            var sysdate2=new Date();
		            sysdate2.setTime(date);
		            if(sysdate1>sysdate2){
		            	$.get(ZBPB_CONST_URL.ISEDIT+'?date='+dateStr,function(data){
                            if("edit"==data.flag){
                                window.location.href = ZBPB_CONST_URL.INIT_VIEW+"?date="+dateStr+"&id="+data.editId;   
                            }
                            if("add"==data.flag){
                            	$.stip({
                                    type : 'danger',//显示类型 有info、 ok、 danger
                                    top : '20px', //显示的X坐标,相对父元素进行决定定位
                                    left : '50%',
                                    text : '请选择今天及以后日期，安排计划!', //显示的tip字符，也可以是html字符串
                                    'min-width' : '300',//自适应
                                    autoHide : 3000, //2000ms , 0表示 立即隐藏 ， false 表示不进行隐藏
                                    beforeShow : function() {
                                    },
                                    beforeHide : function() {
                                    }
                                });
                            }
                        });
		            	
		                
		            }else{
		            	 $.get(ZBPB_CONST_URL.ISEDIT+'?date='+dateStr,function(data){
		            		 if("edit"==data.flag){
		            			 window.location.href = ZBPB_CONST_URL.INIT_EDIT+"?date="+dateStr+"&id="+data.editId; 	
		            		 }
		            		 if("add"==data.flag){
		            			 window.location.href = ZBPB_CONST_URL.INIT_ADD+"?date="+dateStr; 	
		            		 }
		            	 }); 
		            }
		        },
		        eventClick: function(calEvent, jsEvent, view) {
		            var sysdate1=new Date();
		            sysdate1.setHours("8","0","0","0");
		            var sysdate2=new Date();
		            sysdate2.setTime(calEvent.start);
		            sysdate2.setHours("8","0","0","0");
		            if(sysdate1.getTime()<sysdate2.getTime()){
		                 window.location.href = ZBPB_CONST_URL.INIT_EDIT+"?id="+ calEvent.id; 	
		            }else if(sysdate1.getTime()==sysdate2.getTime()){//如果等于今天 
		            	 window.location.href = ZBPB_CONST_URL.INIT_EDIT+"?id="+ calEvent.id; 	
		            }else if(sysdate1.getTime()>sysdate2.getTime()){//如果选择的日期小于今天 的  则只能查看值班信息
		            	window.location.href = ZBPB_CONST_URL.INIT_VIEW+"?id="+ calEvent.id;  
		            }else{
		            	
		            	  //不会进入 这里//alert("今天的值班已安排,确定编辑吗？+4");
		            }
		        },
		         events:  {
		            url: ZBPB_CONST_URL.LIST,
		         	error: function() {
		               
		            }  
		        }  
		    });
		});
		 //请求url
	    var ZBPB_CONST_URL = {
	   		LIST: basePath + '/zhyw/zbpb/list',
	   		ISEDIT: basePath+'/zhyw/zbpb/isEdit',//判断是编辑还是新建
	       	INIT_ADD: basePath + "/zhyw/zbpb/initAdd",
	       	INIT_EDIT: basePath + "/zhyw/zbpb/initEdit",
	       	INIT_ADD_BATCH: basePath + "/zhyw/zbpb/initAddBatch",
	       	INIT_DELETE: basePath + "/zhyw/zbpb/initDelete",
	       	INIT_VIEW: basePath + "/zhyw/zbpb/initView",
	       	INIT_EXPORT: basePath + "/zhyw/zbpb/initExport"
	    };
	</script>     
</body>

</html>